package android.hermes;

import java.net.*;

import android.os.Handler;
import android.os.Message;

public class MultiCastServer extends Thread implements Runnable{

	InetAddress incoming;
	Handler h = new Handler();
	
	public void run() {
		while(true) {
			try {
				//Contents of the packet we send doesn't matter at this point
				byte[] buf = new byte[1];
				buf[0] = (byte) 10101010;				
				DatagramPacket packet = new DatagramPacket(buf, buf.length);
				
				InetAddress group = InetAddress.getByName("10.10.0.1");
				MulticastSocket ms = new MulticastSocket(7500);
				ms.joinGroup(group);
	
				ms.receive(packet);
				incoming = packet.getAddress();
								
				packet = new DatagramPacket(buf, buf.length, incoming, 7501);
				ms.send(packet);
				
				Message msg = new Message();
				msg.obj = incoming;
				msg.what = Hermes.IP;
	
				h.sendMessage(msg);
				
			} catch (Exception e) {
				
			}
		}
	}
}
